package cn.yili12.common.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {

    private TimeUtil() {

    }


    public static String parse(Date date) {
        if (null == date) {
            return "";
        }
        long now = System.currentTimeMillis();
        long time = date.getTime();
        long cha = now - time;
        if (cha < 1000 * 60 * 1) {
            return "刚刚";
        } else if (cha < 1000 * 60 * 60) {
            int min = (int) Math.floor(cha / (1000 * 60));
            return String.format("%d分钟前", min);
        } else if (cha < 1000 * 60 * 60 * 24 * 3) {
            int min = (int) Math.floor(cha / (1000 * 60 * 60));
            return String.format("%d小时前", min);
        } else if (cha < 1000 * 60 * 60 * 24 * 2) {
            int min = (int) Math.floor(cha / (1000 * 60 * 60));
            return String.format("%d小时前", min);
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:MM");
        return simpleDateFormat.format(date);
    }
}
